package com.xiaogang.utils;


/**
 * @Name APIRs
 * @Description 用作统一的api返回
 * @Author 王贞成
 * @CreateDate 2018/7/4
 */
public class APIRs {
    private int code;
    private String msg;
    private Object data;

    public static final int code_success = 200;//请求成功
    public static final int code_success_data_err = 201;//请求数据错误(针对第三方请求)
    public static final int code_success_deal_err = 202;//请求处理错误
    public static final int code_fail = 500;//请求失败
    public static final int code_dev_non_exist = 501;//智能柜不存在
    public static final int code_paramerror=1001;//=参数错误
    public static final int code_tokenerror=1002;//=token为空
    public static final int code_tokenout=1003;//token过期
    public static final int code_params_updatederr=1010;//参数不可修改，已修改过


    public static APIRs success() {
        return success(null);
    }

    public static APIRs fail() {
        return fail(null);
    }

    public static APIRs successMsg(String msg) {
        return new APIRs(code_success, msg, null);
    }
    public static APIRs successDataErr(String msg) {
        return new APIRs(code_success_data_err, msg, null);
    }
    public static APIRs successDealErr(String msg) {
        return new APIRs(code_success_deal_err, msg, null);
    }
    public static APIRs success(Object data) {
        return new APIRs(code_success, "success", data);
    }

    public static APIRs successDevNonExist(String msg) {
        return new APIRs(code_dev_non_exist, msg, null);
    }

    public static APIRs success(String msg,Object data) {
        if(msg==null){
            msg="success";
        }
        return new APIRs(code_success, msg, data);
    }

    public static APIRs fail(Object data) {
        return new APIRs(code_fail, "fail", data);
    }

    public static APIRs fail(String msg) {
        return new APIRs(code_fail, msg, null);
    }

    public static APIRs fail(String msg,Object data) {
        return new APIRs(code_fail, msg, data);
    }

    public static APIRs failParamsError() {
        return new APIRs(code_paramerror, "参数错误", null);
    }
    public static APIRs failParamsError(String msg) {
        return new APIRs(code_paramerror, msg, null);
    }
    public static APIRs failParamsUpdatedError(String msg) {
        return new APIRs(code_params_updatederr, msg, null);
    }
    public static APIRs failTokenErr() {
        return new APIRs(code_tokenerror, "token错误", null);
    }

    public static APIRs failTokenErr(String msg) {
        return new APIRs(code_tokenerror, msg, null);
    }
    public static APIRs failTokenEmpty() {
        return new APIRs(code_tokenerror, "token是空的", null);
    }

    public static APIRs failTokenOut() {
        return new APIRs(code_tokenout, "token过期了", null);
    }

    public APIRs() {
    }

    public APIRs(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "{" +
                "'code':" + code +
                ", 'msg':'" + msg + '\'' +
                ", 'data':" + data +
                '}';
    }
}
